<template>
  <lb-layout
    v-loading="$store.getters.loading"
    element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="#a19f9fb0;"
    :paddBottom="5"
  >
    <aps-form
      :config="apsForm.formConfig"
      :model="apsForm.formData"
      :formRef="apsForm.formRef"
      :labelWidth="apsForm.labelWidth"
      ref="form"
    ></aps-form>
    <lb-table
      style="width: 50%"
      :column="tableData.column"
      :merge="mergeArr"
      :data="tableData.data"
      border
      :height="700"
      background
      layout="total, sizes, prev, pager, next, jumper"
      :page-sizes="[10, 20, 30, 40]"
      :pager-count="5"
      :current-page.sync="currentPage"
      :total="total"
      :page-size="pageSize"
      @size-change="handleSizeChange"
      @p-current-change="handleCurrentChange"
    >
    </lb-table>
  </lb-layout>
</template>
      <script>
import { list } from "@/api/statistics/budgetDeclaration.js";
export default {
  name: "budgetDeclarationStatistics",
  dicts: [],

  data() {
    return {
      mergeArr: ["year"],
      //弹窗
      apsForm: {
        formRef: "form",
        labelWidth: "auto",
        formData: {},
        formConfig: {
          formAttr: {
            inline: true,
            size: "small",
          },
          properties: {
            year: {
              label: "年份:",
              typeName: "el-date-picker",
              type: "year",
              size: "small",
              placeholder: "选择年份",
              "value-format": "yyyy",
            },
          },
          formSoltButton: [
            {
              label: "搜索",
              type: "primary",
              typeName: "el-button",
              size: "small",
              icon: "el-icon-search",
              click: this.handlerSearchDetail,
            },
            {
              label: "重置",
              typeName: "el-button",
              size: "small",
              icon: "el-icon-refresh-left",
              click: this.handleReset,
            },
          ],
        },
      },
      currentPage: 1,
      pageSize: 10,
      total: 0,
      tableData: {
        column: [
          {
            prop: "year",
            label: "年度",
            width: 100,
            align: "center",
            showOverflowTooltip: true,
          },
          {
            prop: "areaName",
            label: "所属地区",
            align: "center",
            showOverflowTooltip: true,
          },
          {
            label: "操作",
            width: 120,
            fixed: "right",
            align: "center",
            render: (h, scope) => {
              let that = this;
              return (
                <div>
                  <el-button
                    type="text"
                    size="small"
                    icon="el-icon-view"
                    onClick={() => {
                      that.$router.push({
                        name: "statisticsBudgetDetail",
                        query: {
                          areaId: scope.row.areaId,
                          year: scope.row.year,
                        },
                      });
                    }}
                  >
                    查看
                  </el-button>
                </div>
              );
            },
          },
        ],
        data: [],
      },
    };
  },
  mounted() {
    this.handlerSearchDetail();
  },
  methods: {
    async initData(data) {
      let that = this;
      let query = {
        ...data,
      };
      query.pageNum = that.currentPage;
      query.pageSize = that.pageSize;
      that.$store.commit("app/updateApiCount", "add");
      await list(query)
        .then((res) => {
          that.$store.commit("app/updateApiCount");
          if (res.code === 700) {
            this.$message.warning(res.msg);
            return false;
          }
          that.tableData.data = res?.data ?? [];
          that.total = res?.total ?? 0;
        })
        .catch((err) => {
          that.$store.commit("app/updateApiCount");
          // this.$message.error("系统错误,请联系管理员!");
        });
    },
    // 搜索
    handlerSearchDetail() {
      const data = {
        parentAreaId: 101,
        ...this.$refs?.form?.getFieldsValue(),
      };
      this.initData(data);
    },
    // 重置
    handleReset() {
      this.$refs?.form?.resetFields();
      this.handlerSearchDetail();
    },
    handleSizeChange(val) {
      this.currentPage = 1;
      this.pageSize = val;
      this.handlerSearchDetail();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.handlerSearchDetail();
    },
  },
};
</script>

      <style lang="scss" scoped>
::v-deep .title {
  .el-tag {
    margin-right: 10px !important;
    margin-bottom: 20px;
  }
}
</style>
